import React, { useEffect, useState } from "react";
import { Button, Form, Input, Select } from "antd";
import axios from "axios";

const Modals = (props) => {
  const [form] = Form.useForm();

  useEffect(() => {
    if (props.title == "编辑") {
      form.setFieldsValue(props.objItem);
    }
  }, []);

  const onFinish = async (values: any) => {
    console.log(values);
    if (props.title == "添加") {
      let obj = {
        id: new Date().getTime(),
        ...values,
      };
      props.onCancel(obj);
    } else {
      let obj = {
        ...props.objItem,
        ...values,
        time: new Date().getTime(),
      };
      props.onOk(obj);
    }
  };

  return (
    <Form form={form} onFinish={onFinish} style={{ maxWidth: 600 }}>
      <Form.Item
        label="商业标题"
        name="khzt"
        rules={[
          {
            required: true,
            message: "请输入商业标题!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="审批状态"
        name="start"
        rules={[
          {
            required: true,
            message: "请输入审批状态!",
          },
        ]}
      >
        <Select
          options={[
            { label: "已通过", value: true },
            { label: "未提交", value: false },
          ]}
        ></Select>
      </Form.Item>
      <Form.Item
        label="关联客户"
        name="name"
        rules={[
          {
            required: true,
            message: "请输入关联客户!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="商机阶段"
        name="khxj"
        rules={[
          {
            required: true,
            message: "请输入商机阶段!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="报价记录"
        name="lxr"
        rules={[
          {
            required: true,
            message: "请输入报价记录!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="报价总金额"
        name="phone"
        rules={[
          {
            required: true,
            message: "请输入报价总金额!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item
        label="未跟进天数"
        name="timefalse"
        rules={[
          {
            required: true,
            message: "请输入未跟进天数!",
          },
        ]}
      >
        <Input />
      </Form.Item>
      <Form.Item>
        <Button type="primary" htmlType="submit">
          确定
        </Button>
      </Form.Item>
    </Form>
  );
};

export default Modals;
